using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using HappyFrogXna.ScreenSystem;
using FarseerPhysics.Factories;

namespace HappyFrogXna.Roles
{
    class RectangleEntity : Entity
    {
        public RectangleEntity(World w, Vector2 pos)
            : base(w, pos)
        { }

        public override Entity Clone()
        {
            Entity entity = EntityCreator.CreateEntity(this.UserDate.Name, _world);//new Entity(world, Position);

            float width = ConvertUnits.ToSimUnits(EntitySprite.Width) * ScaleRadioDisplayOnScreen;
            float height = ConvertUnits.ToSimUnits(EntitySprite.Height) * ScaleRadioDisplayOnScreen;
            float density = EntityBody.FixtureList[0].Shape.Density;
            entity.EntityBody = BodyFactory.CreateRectangle(_world, width, height, density, Position);
            entity.EntityBody.BodyType = this.EntityBody.BodyType;
            entity.EntityBody.Rotation = this.EntityBody.Rotation;
            entity.EntityBody.Mass = this.EntityBody.Mass;
            entity.EntityBody.Restitution = this.EntityBody.Restitution;
            entity.EntityBody.Friction = this.EntityBody.Friction;

            entity.EntitySprite = this.EntitySprite;
            entity.Rotation = this.Rotation;
            entity.IsActive = this.IsActive;
            entity.IsVisible = this.IsVisible;

            entity.UserDate = this.UserDate.Clone();

            return entity;
        }

        public override bool IsTouched(Vector2 pos, float extend)
        {
            return pos.X < Position.X + ConvertUnits.ToSimUnits(EntitySprite.Width + extend) / 2 &&
                pos.X > Position.X - ConvertUnits.ToSimUnits(EntitySprite.Width - extend) / 2 &&
                pos.Y < Position.Y + ConvertUnits.ToSimUnits(EntitySprite.Height + extend) / 2 &&
                pos.Y > Position.Y - ConvertUnits.ToSimUnits(EntitySprite.Height - extend) / 2;
        }
    }
}
